<script>
	import home from '@/api/_home.js'
	export default {
		data(){
			return{
				iskt:false,
				sf:'',
				city:''
			}
		},
		onLaunch: function() {
			console.log('App Launch')
			// 获取地址判断
			this.getaddr()
			
			uni.hideTabBar()
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods:{
			// 获取地址
			getaddr() {
				let _this = this
				uni.getLocation({
					type: 'wgs84',
					success: function(res) {
					},
					fail(r) {
			
					},
					complete(res) {
						let addrdetial=''
						if (res.errMsg == 'getLocation:fail network error') {
							
							_this.iskt = false
							uni.setStorageSync('schoolkt',_this.iskt)
							_this.loading=false
							return
						}
						uni.request({
							url: `https://apis.map.qq.com/ws/geocoder/v1/?location=${res.latitude},${res.longitude}&key=WZ3BZ-ULE6F-KLVJ4-NH2D7-NALA2-HTBTW&get_poi=1`,
							success(r) {
								if (r.data.result.address_component.province == r.data.result
									.address_component.city) {
									addrdetial = r.data.result.address_component.province
								} else {
									addrdetial = r.data.result.address_component.province + r
										.data.result.address_component.city
								}
								uni.setStorageSync('schooladdr',addrdetial)
								_this.sf = r.data.result.address_component.province
								_this.city = r.data.result.address_component.city
								_this.checkaddr()
							}
						})
					}
				});
			},
			checkaddr(){
				let _this=this
				home.checkarea({
					province: _this.sf,
					city: _this.city
				}).then(res => {
					if (res.data.code == 200) {
						_this.iskt = true
						
						uni.setStorage({
							key: 'schoolarea',
							data: res.data.data,
							success() {
								_this.getinit()
								_this.getnotice()
							}
						})
					} else {
						_this.iskt = false
					}
					uni.setStorageSync('schoolkt',_this.iskt)
					
				})
			},
		}
	}
</script>
<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "@/uni_modules/uview-ui/index.scss";
	@font-face {
		font-family: 'Alimama ShuHeiTi-Bold';
		src: url('@/static/AlimamaShuHeiTi-Bold.ttf');
		font-weight: normal;
		font-style: normal;
		font-display: swap;
	}
	@font-face {
		font-family: 'Alegreya';
		src: url('https://mp-b54a63ff-3ce2-4df8-8d6e-f855d8976d34.cdn.bspapp.com/img/Alegreya.ttf');
		font-weight: normal;
		font-style: normal;
		font-display: swap;
	}
	page{
		background-size: cover!important;
	}
</style>